package tests;

import java.util.ArrayList;
import org.junit.*;
import static org.junit.Assert.*;
import main.*; //ugly, but...

public class MyCalendarTest {
	private ArrayList<Event> viewList, calList;
	private CalendarView v;
	private BirthdayView b;
	private MyCalendar cal;

	@Before
	public void initialize() {
		v = new CalendarView("ctc");
		b = new BirthdayView("ctbc");
		cal = new MyCalendar(v, "tc");
		cal.attach(b);
		cal.addEvent(new Event(EventType.Birthday, "John", 13, 1, 2013));
		cal.addEvent(new Event(EventType.Work, "Meeting", 1, 1, 2013));
		viewList = v.getEvents();
		calList = cal.getEvents();
	}

	@Test
	public void test1() {
		for (Event e: viewList)
			assertTrue(calList.contains(e));
		for (Event e: calList)
			assertTrue(viewList.contains(e));
	}

	@Test
	public void test2() {
		cal.detach(v);
	}

	@Test(expected=MinimalSizeException.class)
	public void test3() {
		cal.detach(v);
		cal.detach(v);
	}

	@Test(expected=MaximalSizeException.class)
	public void test4() {
		BirthdayView x = new BirthdayView("toomuch");
		cal.attach(x);
	}

	@Test
	public void test5() {
		for (Event e: calList)
			if (e.getType() == EventType.Birthday)
				assertTrue(b.getEvents().contains(e));
	}
}
